package com.virtual.repository.common.managers;

import java.util.Collection;
import java.util.Map;

import com.virtual.repository.common.model.ModelConfiguration;
import com.virtual.repository.common.queries.Query;
import com.virtual.repository.plugins.api.IDatabasePlugin;

/**
 * Class for each query's manager responsible for the query dividing and merging.
 * @author kchaber
 *
 */
public abstract class AbstractQueryManager {
	/**
	 * The query parser manager - responsible for translating queries and parsing results.
	 */
	protected IQueryParser queryParser;
	
	public AbstractQueryManager() {
		//default query parser
		this.queryParser = new QueryParser();
	}

	/**
	 * Executes the query, asking for possible multiple results.
	 * @param query the <code>Query</code> to be executed.
	 * @return a <code>Collection</code> of requested objects.
	 */
	public abstract <TYPE extends Object> Collection<TYPE> executeQuery(Query query) throws Exception;
	
	/**
	 * Executes the query, asking for a single result only.
	 * @param query the <code>Query</code> to be executed.
	 * @return the single result matching the query.
	 */
	public abstract <TYPE extends Object> TYPE executeQueryForSingleResult(Query query) throws Exception;
	
	/**
	 * Initializes the query manager by setting the model configuration and available database plugins.
	 * @param modelConfig
	 */
	public abstract void initalize(ModelConfiguration modelConfig, Map<String, IDatabasePlugin> plugins);

	public IQueryParser getQueryParser() {
		return queryParser;
	}

	public void setQueryParser(IQueryParser queryParser) {
		this.queryParser = queryParser;
	}
}
